const font_all_menu = [
    { path: 'index', title: '首页', icon: 'home', role: ['manage', 'school'] },
    { path: 'user-list', title: '用户列表', role: ['user'] },
    {
        title: '总部管理中心',
        path: 'headquarters',
        children: [{
                title: '校区管理',
                path: 'school-manager',
                children: [
                    { path: 'school-list', title: '校区列表', role: ['school'] },
                    { path: 'school-new', title: '新建校区', role: ['school'] }
                ]
            },
            {
                title: '部门管理',
                path: 'department-list',
                role: ['manage']
            },
            {
                title: '总部仓库',
                path: 'headquarter-store',
                children: [
                    { path: 'product-list', title: '总部仓库管理', role: ['manage'] },
                    { path: 'product-new', title: '新增产品', role: ['school'] },
                    { path: 'product-category', title: '商品种类', role: ['user'] },
                ]
            }
        ]
    }
];
let result = []

function organize(role, obj, tm_result) {
    if (Array.isArray(obj)) {
        obj.forEach(function(value) {
            let new_array = tm_result.map(value1 => value1)
            organize(role, value, new_array)
        })
    } else {
        if (hasAuthority(role, obj)) {
            tm_result.push({ title: obj.title, path: obj.path })
            result.push(tm_result)
            return
        }
        if (hasChildren(obj)) {
            obj.children.forEach(function(value) {
                let new_array = tm_result.map(value1 => value1)
                new_array.push({ title: obj.title, path: obj.path })
                organize(role, value, new_array)
            })
        }
    }
}

function hasChildren(obj) {
    if (obj.hasOwnProperty('children')) {
        return true
    } else {
        return false
    }
}

function hasAuthority(need_authority, obj) {
    if (obj.hasOwnProperty('role')) {
        if (obj['role'].indexOf(need_authority) > -1) {
            return true
        } else {
            return false
        }
    } else {
        return false
    }
}
organize('school', font_all_menu, [])